import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;

import javax.sql.DataSource;

import mapper.TMapper;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
import com.jolbox.bonecp.BoneCPDataSource;

public class Main
{
    public static void main(String[] args) throws Exception
    {
        Properties properties = new Properties();
        properties.load(TestMain.class.getResourceAsStream("/dataSource.properties"));
        BoneCPConfig boneCPConfig = new BoneCPConfig(properties);
        
        BoneCP boneCp = new BoneCP(boneCPConfig);
        boneCp.getConnection();

        DataSource dataSource = new BoneCPDataSource(boneCPConfig);
        Environment environment = new Environment("product", new JdbcTransactionFactory(), dataSource);
        Configuration configuration = new Configuration(environment);
        configuration.addMappers("mapper");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        TMapper tMapper = sqlSession.getMapper(TMapper.class);
        List<Integer>ids = tMapper.list();
        for(Integer id : ids) {
            System.out.println(id);
        }
        System.out.println(tMapper.check());
        System.out.println(tMapper.s());
        System.out.println(StringEscapeUtils.escapeJavaScript(FileUtils.readFileToString(new File("upload.html"))));
    }
}
